<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>计算年龄</title>
</head>

<body>
    <input type="button" onclick="disp_year()" value="请输入您的出生年份">
    <script type="text/javascript">
        function disp_year() {
            var year = prompt("请输入您的出生年份", "")
            if (year != null && year != "") {
                document.write('您今年' + (2021 - year) + '岁')
            }
        }
    </script>
</body>

</html>